{% extends 'oscar/dashboard/layout.html' %}
{% load i18n %}
{% load render_table from django_tables2 %}

{% block body_class %}{{ block.super }} catalogue{% endblock %}

{% block title %}
    {% trans "Products" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item">
                <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
            </li>
            <li class="breadcrumb-item active" aria-current="page">
                {% trans "Products" %}
            </li>
        </ol>
    </nav>
{% endblock %}

{% block header %}
    <div class="page-header">
        <h1>{% trans "Products" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
    {% block create_product %}
        <div class="table-header">
            <h3><i class="fas fa-sitemap"></i> {% trans "Create new product" %}</h3>
        </div>
        <div class="card card-body">
            <form id="create_product_with_class_form" action="{% url 'dashboard:catalogue-product-create' %}" method="get" class="form-inline">
                {% include "oscar/dashboard/partials/form_fields_inline.html" with form=productclass_form %}
                <button class="btn btn-primary" type="submit" data-loading-text="{% trans 'Submitting...' %}">
                    <i class="fas fa-plus-circle"></i> {% trans "New Product" %}
                </button>
            </form>
        </div>
    {% endblock %}

    {% block search_products %}
        <div class="table-header">
            <h3><i class="fas fa-search"></i> {% trans "Search Products" %}</h3>
        </div>
        <div class="card card-body mb-0">
            <form id="search_product_form" method="get" class="form-inline">
                {% comment %}
                    Add the current query string to the search form so that the
                    sort order is not reset when searching.
                {% endcomment %}
                {% for name, value in request.GET.items %}
                    {% if name not in form.fields %}
                        <input type="hidden" name="{{ name }}" value="{{ value }}"/>
                    {% endif %}
                {% endfor %}

                {% include "oscar/dashboard/partials/form_fields_inline.html" with form=form %}
                <button type="submit" class="btn btn-primary" data-loading-text="{% trans 'Searching...' %}"><i class="fas fa-search"></i> {% trans "Search" %}</button>
            </form>
        </div>
    {% endblock %}

    {% if has_products %}
        {% block product_list %}
            <form method="post">
                {% csrf_token %}
                {% block bulk_action %}
                    {% trans "Products" as module_label %}
                    {% include "oscar/dashboard/partials/bulk_actions.html" with page_objects_count=products.page.object_list.data.count num_pages=products.paginator.num_pages total_count=products.paginator.count module=module_label %}
                {% endblock bulk_action %}
                {% block product_table %}
                    {% render_table products %}
                {% endblock product_table %}
            </form>
            <div class="modal fade" id="product-image-modal" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title"></h4>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        </div>
                        <div class="modal-body text-center">
                            <img class="img-fluid mx-auto">
                        </div>
                    </div>
                </div>
            </div>
        {% endblock product_list %}
    {% else %}
        <p>{% trans "No products found." %}</p>
    {% endif %}

{% endblock dashboard_content %}

{% block onbodyload %}
    {{ block.super }}
    oscar.dashboard.product_lists.init();
    oscar.dashboard.bulk_actions.init();
{% endblock onbodyload %}
